package com.easy;

import java.util.Stack;

/**
 * Created by Lxk on 2020/2/9.
 */
public class Solution155 {

    private Stack<Integer> stack;

    private Stack<Integer> helpStack;

    public Solution155() {
        stack = new Stack<>();
        helpStack = new Stack<>();
    }

    public void push(int x) {
        stack.push(x);
        if (helpStack.isEmpty()) {
            helpStack.push(x);
        } else {
            if (helpStack.peek() < x) {
                helpStack.push(helpStack.peek());
            } else {
                helpStack.push(x);
            }
        }
    }

    public void pop() {
        stack.pop();
        helpStack.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return helpStack.peek();
    }

    public static void main(String[] args) {
        Solution155 solution155 = new Solution155();
        solution155.push(-2);
        solution155.push(0);
        solution155.push(-3);
        System.out.println(solution155.getMin());
        solution155.pop();
        System.out.println(solution155.top());
        System.out.println(solution155.getMin());
    }

}
